﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    DataDataContext data = new DataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        CusLog_in(txtuser.Text, txtpass.Text);
    }
    public void CusLog_in(string user, string password)
    {

        if (txtuser.Text == "")
        {
            lblLoi.Visible = true;
            lblLoi.Text = "Username not null";
        }
        else if (txtpass.Text == "")
        {
            lblLoi.Visible = true;
            lblLoi.Text = "Password not null";
        }
        string chuoi = Encript.mahoa(password);
        try
        {
            var Customer = (from cus in data.tblCustomers
                            where cus.Customer_Username == user && cus.Customer_Password == chuoi
                            select cus).FirstOrDefault();
            if (Customer.Customer_Username == txtuser.Text && Customer.Customer_Password == chuoi)
            {

                Response.Write("<script>alert('ban da dang nhap thanh cong')</script>");
                Session["CustomerName"] = user;
                Response.Redirect("Home.aspx");
            }


        }
        catch (Exception ex)
        {
            ex.ToString();
            lblLoi.Visible = true;
            lblLoi.Text = "Username or Password khong dung";

        }

    }
    protected void lbtn_register_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Forgot password.aspx");
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Home.aspx");
    }
}